<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link href="../../../static/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link rel="stylesheet" href="../../../static/vui/css/vui.css">

	<script type="text/javascript" src="../../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../../static/js/jquery.cookie.min.js"></script>
	<script src="../../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../../static/laydate/laydate.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/vui.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/datagrid.js"></script>
	<script type="text/javascript" src="../../../static/js/common.js"></script>
</head>
<body>

<div id="formArea">
	<table class="table-top">
		<tr>
			<td>
				<label class="label">单据日期</label>
			</td>
			<td>
				<input type="text" n="date" class="input search-date" name="dateStart" autocomplete="off"/>&nbsp;-&nbsp;
				<input type="text" n="date" class="input search-date" name="dateEnd" autocomplete="off"/>
			</td>
			<td>
				<button class="button" id="query"><span>查询</span></button>
				<button class="button" id="create"><span>新增</span></button>
			</td>
		</tr>
	</table>
</div>

<div id="table"></div>

<script>
    $(function(){
        var params = app.getRequestParams();

        $('#create').click(function(){
            location.href = 'receipt_add.html?type='+params.type;
        });

        $('#query').click(function(){
            $("#table").datagrid("reload",app.serializeForm());
        });

        var nowDate = app.time2str(new Date()),startDate = new Date(nowDate.substr(0,8)+'01');
        dateStart = laydate.render({
            elem: 'input[name="dateStart"]',value:startDate,max:nowDate,
            done: function(value,date){
                if(value){
                    console.log(date);
                    date.month=date.month-1;
                    dateEnd.config.min = date;
                }else{
                    dateEnd.config.min=dateStart.config.min;
                }
            }
        });
        dateEnd = laydate.render({
            elem: 'input[name="dateEnd"]',value:nowDate,min:nowDate.substr(0,8)+'01',
            done: function(value,date){
                if(value){
                    date.month=date.month-1;
                    dateStart.config.max = date;
                }else{
                    dateStart.config.max=dateEnd.config.max;
                }
            }
        });

        $('#reset').click(function () {
            $('#formArea input').val('');

            var endDate = app.time2str(new Date());
            var startDate = endDate.substr(0,8)+'01';
            $('input[name="dateStart"]').val(startDate);

            dateEnd.config.min = {year:getYear(startDate),month:getMonth(startDate),date:getDate(startDate)};

            $('input[name="dateEnd"]').val(endDate);
            dateStart.config.max = {year:getYear(endDate),month:getMonth(endDate),date:getDate(endDate)};


        });

        function getYear(dateStr){
            return parseInt(dateStr.split('-')[0]);
        }

        function getMonth(dateStr){
            return parseInt(dateStr.split('-')[1])-1;
        }

        function getDate(dateStr){
            return parseInt(dateStr.split('-')[2]);
        }

        $("#table").datagrid({
            url:app.BASE_API_URL+'receipt/page',
            queryParams:{dateStart:startDate.getTime(),dateEnd:new Date().getTime(),type:params.type},
            columns:[
                {field:'date',title:'收款日期',width:100,formatter:app.timeFormatter},
                {field:'code',title:'收款编号',width:180,formatter:function (row) {
                    var codePrefit = params.type == 1 ? 'SK':'FK';
                        return '<a class="a" href="./receipt_add.html?type='+params.type+'&id='+row.id+'">'+codePrefit+row.code+'</a>';
				}},
                {field:'relationName',title:'付款单位',width:120},
                {field:'relationType',title:'付款单位类别',width:120,formatter:function (row) {
						return row.relationType == 1?"供应商":row.relationType == 2?"客户":'';
                    }},
                {field:'receiptMoney',title:'收款金额',width:100,n:'money'},
                {field:'verificateMoney',title:'核销金额',width:100,n:'money'},
                {field:'userName',title:'收款人',width:100,},
                {field:'remarks',title:'备注',width:100,},
                {field:'status',title:'单据状态',width:100,formatter:function (row) {
					if( row.status == '1' ){
						return app.getLable('未审核','warning');
					}else if( row.status == '2' ){
						return app.getLable('已审核','success');
					}else{
						return '状态异常';
					}
				}}
            ]
        });
    });
</script>

</body>
</html>